# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import fields, models

from odoo.addons.base_import_patch.models.base_import import _load_records_get_data_list


class Partner(models.Model):
    _inherit = 'res.partner'

    def _load_records(self, data_list, update=False):
        # # laod data, check if create or update
        data_list2 = _load_records_get_data_list(self, data_list)
        return super()._load_records(data_list2, update)

    # def _load_records(self, data_list, update=False):
    #     # get_values 的 例子
    #     # 解决  m2o2_id 的 name 不唯一的问题
    #     def get_values(values):
    #         values2 = values.copy()
    #         domain = [('name', '=', values['name']),
    #                   ('m2o_id', '=', values['m2o2_id'])]
    #         m2o2_id = self.env['res.xxxxx'].search(domain, limit=1)
    #         values2.update({'m2o2_id': m2o2_id.id})
    #         return values2

    #     unique_fields = ['name']
    #     data_list2 = _load_records_get_data_list(
    #         self, data_list, unique_fields, get_values=get_values)
    #     return super()._load_records(data_list2, update)
